package kr.co.sdworld.webclient.spring.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import kr.co.sdworld.api.apns.model.ApnsTokenSample;
import kr.co.sdworld.api.apns.service.AppService;
import kr.co.sdworld.api.apns.service.TokenService;
import kr.co.sdworld.api.apns.service.base.ListResult;
import kr.co.sdworld.stone.ListParam;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class CT_List 
{
	@Autowired
	private TokenService tokenService;
	@Autowired
	private AppService apnsAppService;
	
	@RequestMapping("/ajaxList.sd")
	public ModelAndView ajaxList( HttpServletRequest request) 
	{
		ModelAndView mnv = new ModelAndView("jsonView");
		
		String appId = request.getParameter( "appId");
		String funcId = request.getParameter( "funcId");
		
		if( "sampleTokenList".equals(funcId)) 
		{
			List<ApnsTokenSample> tokenList = tokenService.getTokenSampleListByAppId(appId);
			mnv.addObject("sampleTokenList", tokenList);
		}
		else if( "appList".equals(funcId))
		{
			ListParam param = new ListParam();
			param.setMaxRow(20);
			param.setPageNum(1);
			ListResult result = apnsAppService.getApnsAppList(param);
			mnv.addObject("appList", result);
		}
		return mnv;
	}
}
